package cn.com.smart.module.ai.aiImg.controller;

import cn.com.smart.common.utils.poi.ExcelUtil;
import cn.com.smart.framework.aspectj.lang.annotation.Log;
import cn.com.smart.framework.aspectj.lang.enums.BusinessType;
import cn.com.smart.framework.web.controller.BaseController;
import cn.com.smart.framework.web.domain.AjaxResult;
import cn.com.smart.framework.web.page.TableDataInfo;
import cn.com.smart.module.ai.aiImg.domain.AiImg;
import cn.com.smart.module.ai.aiImg.service.IAiImgService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 摄像头图片信息信息操作处理
 * 
 * @author xman
 * @date 2020-03-05
 */
@Controller
@RequestMapping("/door/aiImg")
public class AiImgController extends BaseController
{
    private String prefix = "door/aiImg";
	
	@Autowired
	private IAiImgService aiImgService;
	
	@RequiresPermissions("door:aiImg:view")
	@GetMapping()
	public String aiImg()
	{
	    return prefix + "/aiImg";
	}
	
	/**
	 * 查询摄像头图片信息列表
	 */
	@RequiresPermissions("door:aiImg:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(AiImg aiImg)
	{
		startPage();
        List<AiImg> list = aiImgService.selectAiImgList(aiImg);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出摄像头图片信息列表
	 */
	@RequiresPermissions("door:aiImg:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AiImg aiImg)
    {
    	List<AiImg> list = aiImgService.selectAiImgList(aiImg);
        ExcelUtil<AiImg> util = new ExcelUtil<AiImg>(AiImg.class);
        return util.exportExcel(list, "aiImg");
    }
	
	/**
	 * 新增摄像头图片信息
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存摄像头图片信息
	 */
	@RequiresPermissions("door:aiImg:add")
	@Log(title = "摄像头图片信息", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(AiImg aiImg)
	{		
		return toAjax(aiImgService.insertAiImg(aiImg));
	}

	/**
	 * 修改摄像头图片信息
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		AiImg aiImg = aiImgService.selectAiImgById(id);
		mmap.put("aiImg", aiImg);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存摄像头图片信息
	 */
	@RequiresPermissions("door:aiImg:edit")
	@Log(title = "摄像头图片信息", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(AiImg aiImg)
	{		
		return toAjax(aiImgService.updateAiImg(aiImg));
	}
	
	/**
	 * 删除摄像头图片信息
	 */
	@RequiresPermissions("door:aiImg:remove")
	@Log(title = "摄像头图片信息", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(aiImgService.deleteAiImgByIds(ids));
	}
	
}
